/*Problem Id:1033  User Id:tq 
Memory:24K  Time:15MS
Language:C++  Result:Accepted

	author: TangQiao , Wind @ Beijing Normal University

	problem name: Tree Recovery
	
	source :  BNU Online Judge
	
	problem type: 图论 树
	
	problem description: 已知前序及中序遍历,求树的后序遍历.

	date : 2005.7.12 北师大校队个人练习赛4
	
*/
#include <stdio.h>
#include <string.h>

char s1[30],s2[30];

struct treedef
{
	char nod;	
	int left;
	int right;
}tree[50];

int num;

void di(int &num,int a1,int a2, int b1, int b2)
{
	int i, mid, now;
	
	now=num;
	if (a1==a2)
	{
		tree[num].nod=s1[a1];
		tree[num].left=tree[num].right=0;
	}
	else if (a1>a2 || b1>b2)
	{
		tree[num].nod=0;
		tree[num].left=tree[num].right=0;
	}
	else
	{
		tree[num].nod=s1[a1];	
		
		for (i=b1;i<=b2;i++)
			if (s1[a1]==s2[i])
			{
				mid=i;
				break;
			}
		num++;
		tree[now].left=num;
		di(num,a1+1,a1+mid-b1,b1,mid-1);
		num++;
		tree[now].right=num;
		di(num,a1+mid-b1+1,a2,mid+1,b2);
	}

}

void output(int i)
{
	if (tree[i].left!=0)
	{
		output(tree[i].left);
	}
	if (tree[i].right!=0)
	{
		output(tree[i].right);
	}
	if (tree[i].nod!=0) 
		printf("%c",tree[i].nod);
}


main()
{
	int site;
	while (scanf("%s %s", s1, s2)!=EOF)
	{
		memset(tree,0,sizeof(tree));
		num=1;
		site=strlen(s1)-1;
		di(num,0,site,0,site);
		output(1);
		printf("\n");
	}
	return 0;
}
